package com.atguigu.springcloud.service.impl;

import cn.hutool.core.util.IdUtil;
import com.atguigu.springcloud.service.IMessageProviderService;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

/**
 * @ClassName MessageProviderServiceImpl
 * @Desscription
 * @Author _HeiShuai
 * @Date 2023/1/6 15:07
 * @Version 1.0
 **/
@EnableBinding(Source.class)
public class MessageProviderServiceImpl implements IMessageProviderService {

    /**
     * 消息发送管道/信道
     */
    @Resource
    private MessageChannel output;

    @Override
    public String send() {
        String simpleUUID = IdUtil.simpleUUID();
        output.send(MessageBuilder.withPayload(simpleUUID).build());
        System.out.println("*****simpleUUID: " + simpleUUID);
        return simpleUUID;
    }
}
